#
# Scanner Class
#

require 'soul/core'

module Soul

class Scanner

	extend Soul::Primitives

	# Default Char Scanner
	@@k = { :char => any }

	# Define Skip Parser
	def self.skip(parser)
		@@skip = parser
	end

	# Define Rules
	def self.rules(rules)
		@@k    = rules
	end
	
	def initialize(input = '')
		self.load(input)
	end

	def get
		@input[@i += 1]
	end

	def to_str
		@input[@i]
	end

	def next
		return if (k = self.get) == nil
		@@k.each { |t, m| return t if m.include? k }
	end

	def load(input)
		@i		  = -1
		@input  = input
		@end		= input.size - 1
	end

	def scan(what=nil)
		self.load(what) if what
		result = []	
		while x = self.next
			result <<  x
		end

		result
	end

end

end # Soul
